//============================================================================
// Copyright (C) 2010 Brett R. Jones
// All Rights Reserved
//
// You may redistribute and/or modify for non commercial and commercial uses
// provided this copyright notice remains in place and is not modified
//
// This code is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
//
// brettjones1900@gmail.com
// http://www.p2panarchy.com
//============================================================================

#include "DtwGame.h"

//------------------------------------------------------------------------------
//! clear any buttons etc from previous menu
void DtwStateMenu::ClearPreviousMenu( void )
{
	m_poGui->clear();
	m_oTutorialTextInfo.m_strText = "";
	m_u32Timer = 0;
}

//------------------------------------------------------------------------------
//! build main menu
RCODE DtwStateMenu::InitMenuMain( void )
{
	log_msg( 0, "Init Menu Main\n");
	ClearPreviousMenu();
	m_eCurMenuState = eMenuStateMain;
	int iCenterX = m_poDriver->getScreenSize().Width / 2;
	int iCenterY = m_poDriver->getScreenSize().Height / 2;
	
	// destroy the world logo

	// resize logo to fit window
	irr::f32 f32ScaledHeight = (m_poDriver->getScreenSize().Width/480.0f) * 120;
	irr::gui::IGUIImage * poImage = m_poGui->addImage( GetRect( 0, 0, m_poDriver->getScreenSize().Width, (int) f32ScaledHeight)  );
	poImage->setScaleImage( true );
	poImage->setUseAlphaChannel( true );
	poImage->setImage( m_poDriver->getTexture( GetAssetPathAndName( "dtw_logo_480w.png", eGameAssetTypeGui )) );
	poImage->setScaleImage( true );
	poImage->setUseAlphaChannel( true );

	// show game version
	irr::core::stringw strGameVersion;
	strGameVersion.Format( "Version: %3.2f", DTW_GAME_VERSION );
	irr::gui::IGUIStaticText * poTextVersion = m_poGui->addStaticText( strGameVersion.c_str(),
			GetCenteredRect(150,  m_poDriver->getScreenSize().Height - 20, 200, 15), false, false );
	irr::core::stringw strCopywrite( L"Copywrite (C) Brett R. Jones");
	irr::gui::IGUIStaticText * poTextCopywrite = m_poGui->addStaticText( strCopywrite.c_str(),
			GetCenteredRect(150,  m_poDriver->getScreenSize().Height - 70, 200, 15), false, false );

	// setup buttons
	int iY = iCenterY - (int)(50 * m_f32ScaleHeight);
	irr::gui::IGUIButton * poPlayBut		= m_poGui->addButton( 
				GetCenteredRect( 
						iCenterX, 
						iY, 
						(int)(130 * m_f32ScaleWidth),
						(int)(34 * m_f32ScaleHeight) ), 
						0, EGUI_MAIN_PLAY_BUT, L"Play" );

	irr::gui::IGUIButton * poOptionsBut		= m_poGui->addButton( 
				GetCenteredRect( 
						iCenterX, 
						iY + (int)(50 * m_f32ScaleHeight), 
						(int)(130 * m_f32ScaleWidth), 
						(int)(34 * m_f32ScaleHeight) ), 
						0, EGUI_MAIN_OPTIONS_BUT, L"Options");

	irr::gui::IGUIButton * poHighScoresBut	= m_poGui->addButton( 
				GetCenteredRect( 
						iCenterX, 
						iY + (int)(100 * m_f32ScaleHeight), 
						(int)(130 * m_f32ScaleWidth), 
						(int)(34 * m_f32ScaleHeight) ), 
						0, EGUI_MAIN_HIGHSCORE_BUT, L"High Scores");

	irr::gui::IGUIButton * poQuitBut		= m_poGui->addButton( 
				GetCenteredRect( 
						iCenterX, 
						iY + (int)(150 * m_f32ScaleHeight), 
						(int)(130 * m_f32ScaleWidth), 
						(int)(34 * m_f32ScaleHeight) ), 
						0, EGUI_MAIN_EXIT_BUT, L"Quit");

	poPlayBut->setImage( m_apoGuiImages[ eGuiImageButton128x32 ] );
	poPlayBut->setScaleImage( true ); 
	poPlayBut->setUseAlphaChannel(true);
	poPlayBut->setOverrideFont( GetFont( m_eDefaultFontSize ) );

	poHighScoresBut->setImage( m_apoGuiImages[ eGuiImageButton128x32 ] );
	poHighScoresBut->setScaleImage( true ); 
	poHighScoresBut->setUseAlphaChannel(true);
	poHighScoresBut->setOverrideFont( GetFont( m_eDefaultFontSize ) );

	poOptionsBut->setImage( m_apoGuiImages[ eGuiImageButton128x32 ] );
	poOptionsBut->setScaleImage( true ); 
	poOptionsBut->setUseAlphaChannel(true);
	poOptionsBut->setOverrideFont( GetFont( m_eDefaultFontSize ) );

	poQuitBut->setImage( m_apoGuiImages[ eGuiImageButton128x32 ] );
	poQuitBut->setUseAlphaChannel(true);
	poQuitBut->setScaleImage( true ); 
	poQuitBut->setOverrideFont( GetFont( m_eDefaultFontSize ) );
	log_msg( 0, "Init Menu Main done\n");

	return 0;
}
//------------------------------------------------------------------------------
//! build menu to choose game play difficulty
RCODE DtwStateMenu::InitMenuChooseDifficulty( void )
{
	ClearPreviousMenu();
	m_eCurMenuState = eMenuStateChooseDifficulty;
	int iCenterX = m_poDriver->getScreenSize().Width / 2;
	int iCenterY = m_poDriver->getScreenSize().Height / 2;


	irr::gui::IGUIStaticText * poTitleText = m_poGui->addStaticText( L"Game Difficulty",  
		GetCenteredRect( 
					iCenterX, 
					iCenterY - (int)(140 * m_f32ScaleHeight),
					(int)( 260 * m_f32ScaleWidth ),
					(int)( 40  * m_f32ScaleHeight ) ), 
					false, false );
	poTitleText->setOverrideFont( m_apoFonts[ eGuiFontLarge ] );
	poTitleText->setTextAlignment( irr::gui::EGUIA_CENTER, irr::gui::EGUIA_UPPERLEFT );

	// setup buttons
	irr::gui::IGUIButton * poEasyBut	= m_poGui->addButton( 
				GetCenteredRect( 
						iCenterX, 
						iCenterY - (int)(100 * m_f32ScaleHeight),
						(int)(130 * m_f32ScaleWidth), 
						(int)(34 * m_f32ScaleHeight) ), 
						0, EGUI_PLAY_EASY_BUT, L"EASY" );
	irr::gui::IGUIButton * poHardBut	= m_poGui->addButton( 
				GetCenteredRect( 
						iCenterX, 
						iCenterY - (int)(50 * m_f32ScaleHeight),
						(int)(130 * m_f32ScaleWidth), 
						(int)(34 * m_f32ScaleHeight) ), 
						0, EGUI_PLAY_MEDIUM_BUT, L"MEDIUM" );
	irr::gui::IGUIButton * poOmgBut	= m_poGui->addButton( 
				GetCenteredRect( 
						iCenterX, 
						iCenterY,
						(int)(130 * m_f32ScaleWidth), 
						(int)(34 * m_f32ScaleHeight) ), 
						0, EGUI_PLAY_HARD_BUT, L"HARD" );
	irr::gui::IGUIButton * poTutorialBut	= m_poGui->addButton(
				GetCenteredRect(
						iCenterX,
						iCenterY + (int)(50 * m_f32ScaleHeight),
						(int)(130 * m_f32ScaleWidth),
						(int)(34 * m_f32ScaleHeight) ),
						0, EGUI_PLAY_TUTORIAL, L"TUTORIAL" );
	// back
	irr::gui::IGUIButton * poBackBut = m_poGui->addButton( 
				GetCenteredRect(
						iCenterX, 
						iCenterY + (int)(100 * m_f32ScaleHeight),
						(int)(82 * m_f32ScaleWidth), 
						(int)(34 * m_f32ScaleHeight) ), 
						0, EGUI_PLAY_BACK_BUT, L"Back");


	poEasyBut->setImage( m_apoGuiImages[ eGuiImageButton128x32 ] );
	poEasyBut->setUseAlphaChannel(true);
	poEasyBut->setScaleImage( true ); 
	poEasyBut->setOverrideFont( GetFont( m_eDefaultFontSize ) );

	poHardBut->setImage( m_apoGuiImages[ eGuiImageButton128x32 ] );
	poHardBut->setUseAlphaChannel(true);
	poHardBut->setScaleImage( true ); 
	poHardBut->setOverrideFont( GetFont( m_eDefaultFontSize ) );

	poOmgBut->setImage( m_apoGuiImages[ eGuiImageButton128x32 ] );
	poOmgBut->setUseAlphaChannel(true);
	poOmgBut->setScaleImage( true ); 
	poOmgBut->setOverrideFont( GetFont( m_eDefaultFontSize ) );

	poTutorialBut->setImage( m_apoGuiImages[ eGuiImageButton128x32 ] );
	poTutorialBut->setUseAlphaChannel(true);
	poTutorialBut->setScaleImage( true );
	poTutorialBut->setOverrideFont( GetFont( m_eDefaultFontSize ) );

	poBackBut->setImage( m_apoGuiImages[ eGuiImageButton80x32 ] );
	poBackBut->setUseAlphaChannel(true);
	poBackBut->setScaleImage( true ); 
	poBackBut->setOverrideFont( GetFont( m_eDefaultFontSize ) );


	return 0;
}
//------------------------------------------------------------------------------
//! build menu showing config options
RCODE DtwStateMenu::InitMenuOptions( void )
{
	ClearPreviousMenu();
	m_eCurMenuState = eMenuStateOptions;
	int iCenterX = m_poDriver->getScreenSize().Width / 2;
	int iCenterY = m_poDriver->getScreenSize().Height / 2;

	int iCurYPos = iCenterY - (120* m_f32ScaleHeight);
	irr::gui::IGUIStaticText * poTitleText = m_poGui->addStaticText( L"Options",  GetCenteredRect( iCenterX, iCurYPos, (150 * m_f32ScaleWidth), (40 * m_f32ScaleHeight) ), false, false );
	poTitleText->setOverrideFont( m_apoFonts[ eGuiFontLarge ] );
	poTitleText->setTextAlignment( irr::gui::EGUIA_CENTER, irr::gui::EGUIA_UPPERLEFT );


	iCurYPos += (40* m_f32ScaleHeight);
	// setup buttons
	irr::gui::IGUIButton * poVideoBut	= m_poGui->addButton( GetCenteredRect( iCenterX, iCurYPos, (130 * m_f32ScaleWidth), (34 * m_f32ScaleHeight)), 0, EGUI_OPTIONS_VIDEO, L"Video" );
	iCurYPos += (40* m_f32ScaleHeight);
	irr::gui::IGUIButton * poAudioBut	= m_poGui->addButton( GetCenteredRect( iCenterX, iCurYPos, (130 * m_f32ScaleWidth), (34 * m_f32ScaleHeight)), 0, EGUI_OPTIONS_AUDIO, L"Audio" );
	iCurYPos += (40* m_f32ScaleHeight);
	irr::gui::IGUIButton * poBackBut	= m_poGui->addButton( GetCenteredRect( iCenterX, iCurYPos, (130 * m_f32ScaleWidth), (34 * m_f32ScaleHeight)), 0, EGUI_OPTIONS_BACK, L"Back" );
	iCurYPos += (40* m_f32ScaleHeight);
	poVideoBut->setImage( m_apoGuiImages[ eGuiImageButton128x32 ] );
	poVideoBut->setUseAlphaChannel(true);
	poVideoBut->setOverrideFont( GetFont( m_eDefaultFontSize ) );
	poVideoBut->setScaleImage( true );

	poAudioBut->setImage( m_apoGuiImages[ eGuiImageButton128x32 ] );
	poAudioBut->setUseAlphaChannel(true);
	poAudioBut->setOverrideFont( GetFont( m_eDefaultFontSize ) );
	poAudioBut->setScaleImage( true );

	poBackBut->setImage( m_apoGuiImages[ eGuiImageButton128x32 ] );
	poBackBut->setUseAlphaChannel(true);
	poBackBut->setOverrideFont( GetFont( m_eDefaultFontSize ) );
	poBackBut->setScaleImage( true );

	return 0;

}
//------------------------------------------------------------------------------
//! build menu video settings
RCODE DtwStateMenu::InitMenuVideo( void )
{
	ClearPreviousMenu();
	m_eCurMenuState = eMenuStateVideo;
	int iCenterX = m_poDriver->getScreenSize().Width / 2;
	int iCenterY = m_poDriver->getScreenSize().Height / 2;

	// title
	int X = iCenterX;
	int Y = iCenterY - (150* m_f32ScaleHeight);
	irr::gui::IGUIStaticText * poTitleText = m_poGui->addStaticText(L"Video",  GetCenteredRect(X, Y, 150, 40), false, false);
	poTitleText->setOverrideFont( m_apoFonts[ eGuiFontLarge ] );
	poTitleText->setTextAlignment( irr::gui::EGUIA_CENTER, irr::gui::EGUIA_UPPERLEFT );


	// Shadows
	Y += (30* m_f32ScaleHeight);
	irr::gui::IGUIStaticText * poTextShadows = m_poGui->addStaticText(L"Shadows", GetCenteredRect(X - 65, Y, 110, 25), false, false);
	poTextShadows->setTextAlignment( irr::gui::EGUIA_LOWERRIGHT, irr::gui::EGUIA_CENTER );
	irr::gui::IGUICheckBox * poCheckBoxShadows = m_poGui->addCheckBox( g_UserConfigImp.m_bShadows,  GetCenteredRect(X + 60, Y, 100, 25), 0, EGUI_VIDEO_SHADOWS );

	// antialias
	Y += (30* m_f32ScaleHeight);
	irr::gui::IGUIStaticText * poTextAntiAlias = m_poGui->addStaticText(L"Antialias",  GetCenteredRect(X - 65, Y, 110, 25) );
	poTextAntiAlias->setTextAlignment( irr::gui::EGUIA_LOWERRIGHT, irr::gui::EGUIA_CENTER);
	irr::gui::IGUICheckBox * poCheckBoxAntialias = m_poGui->addCheckBox( g_UserConfigImp.m_iAntiAliasing,  GetCenteredRect(X + 60, Y, (100 * m_f32ScaleWidth), 25), 0, EGUI_VIDEO_ANTIALIAS );

	// save / cancel
	Y += (90* m_f32ScaleHeight);
	irr::gui::IGUIButton *poButtonSave = m_poGui->addButton( GetCenteredRect(X - (50 * m_f32ScaleWidth), Y, (82 * m_f32ScaleWidth), (34* m_f32ScaleHeight)), 0, EGUI_VIDEO_SAVE, L"Save");
	irr::gui::IGUIButton *poButtonCancel = m_poGui->addButton( GetCenteredRect(X + (50 * m_f32ScaleWidth), Y, (82 * m_f32ScaleWidth), (34* m_f32ScaleHeight)), 0, EGUI_VIDEO_CANCEL, L"Cancel");
	poButtonSave->setImage( m_apoGuiImages[ eGuiImageButton80x32 ] );
	poButtonSave->setUseAlphaChannel(true);
	poButtonSave->setScaleImage( true );
	//poButtonSave->setOverrideFont( GetFont( m_eDefaultFontSize ) );

	poButtonCancel->setImage( m_apoGuiImages[ eGuiImageButton80x32 ] );
	poButtonCancel->setUseAlphaChannel(true);
	poButtonCancel->setScaleImage( true );
	//poButtonCancel->setOverrideFont( GetFont( m_eDefaultFontSize ) );

	// applied later warning
	Y += (40* m_f32ScaleHeight);
	irr::gui::IGUIStaticText * poTextWarning = m_poGui->addStaticText( L"Some changes are applied after restart",  GetCenteredRect(X, Y, 250, 25), false, false, 0, -1, true);
	poTextWarning->setTextAlignment( irr::gui::EGUIA_CENTER, irr::gui::EGUIA_CENTER );

	return 0;
}
//------------------------------------------------------------------------------
//! build menu showing audio settings
RCODE DtwStateMenu::InitMenuAudio( void )
{
	ClearPreviousMenu();
	ChangeSkin( eGuiSkinTypeNeedSlider );
	m_eCurMenuState = eMenuStateAudio;
	int iCenterX = m_poDriver->getScreenSize().Width / 2;
	int iCenterY = m_poDriver->getScreenSize().Height / 2;

	// title
	int X = iCenterX;
	int Y = iCenterY - 150;
	irr::gui::IGUIStaticText * poTitleText = m_poGui->addStaticText(L"Audio",  GetCenteredRect(X, Y, 150, 40), false, false);
	poTitleText->setOverrideFont( m_apoFonts[ eGuiFontLarge ] );
	poTitleText->setTextAlignment( irr::gui::EGUIA_CENTER, irr::gui::EGUIA_UPPERLEFT );

	// Audio enabled
	//irr::gui::IGUIStaticText * poTextAudioEnabled = m_poGui->addStaticText(L"Audio Enabled", GetCenteredRect(X - 50, Y, 82, 34), false, false);
	//irr::gui::IGUICheckBox * poCheckBoxAudioEnabled = m_poGui->addCheckBox(Config::Instance().AudioEnabled, GetCenteredRect(X - 50, Y, 82, 34), 0, AUDIO_ENABLED);

	// Sound Effects Volume
	Y += 50;
	irr::gui::IGUIStaticText * poTextSoundVolume= m_poGui->addStaticText(L"Sound Volume", GetCenteredRect(X, Y, 300, 34), false, false);
	Y += 30;
	irr::gui::IGUIScrollBar * poScrollBarSoundVolume = m_poGui->addScrollBar(1, GetCenteredRect(X, Y, 300, 34), 0, EGUI_AUDIO_SOUND_VOLUME);
	poScrollBarSoundVolume->setMax(100);
	poScrollBarSoundVolume->setPos((int)(g_UserConfigImp.m_f32SoundVolume * 100));


	//Y += 50;
	//irr::gui::IGUIStaticText * poTextMusicVolume= m_poGui->addStaticText(L"Music Volume", GetCenteredRect(X, Y, 300, 34), false, false);
	//Y += 30;
	//irr::gui::IGUIScrollBar * poScrollBarMusicVolume = m_poGui->addScrollBar(1, GetCenteredRect(X, Y, 300, 34), 0, EGUI_AUDIO_MUSIC_VOLUME);
	//poScrollBarMusicVolume->setMax(100);
	//poScrollBarMusicVolume->setPos((int)(g_UserConfigImp.m_f32MusicVolume * 100));


	// save / cancel
	Y += 90;
	irr::gui::IGUIButton * poSaveBut = m_poGui->addButton( GetCenteredRect(X - 50, Y, 82, 34), 0, EGUI_AUDIO_SAVE, L"Save");
	irr::gui::IGUIButton * poCancelBut = m_poGui->addButton( GetCenteredRect(X + 50, Y, 82, 34), 0, EGUI_AUDIO_CANCEL, L"Cancel");

	poSaveBut->setImage( m_apoGuiImages[ eGuiImageButton80x32 ] );
	poSaveBut->setUseAlphaChannel(true);
	poSaveBut->setScaleImage( true );
	//poSaveBut->setOverrideFont( GetFont( m_eDefaultFontSize ) );

	poCancelBut->setImage( m_apoGuiImages[ eGuiImageButton80x32 ] );
	poCancelBut->setUseAlphaChannel(true);
	poCancelBut->setScaleImage( true );
	//poCancelBut->setOverrideFont( GetFont( m_eDefaultFontSize ) );

	// applied later warning
	//Y += 40;
	//irr::gui::IGUIStaticText * poTextWarning = m_poGui->addStaticText( L"Some changes are applied after restart",  GetCenteredRect(X, Y, 250, 25), false, false, 0, -1, true);
	//poTextWarning->setTextAlignment( irr::gui::EGUIA_CENTER, irr::gui::EGUIA_CENTER );


	return 0;
}
//------------------------------------------------------------------------------
//! build menu to select tutorial
RCODE DtwStateMenu::InitMenuTutorial( void )
{
	ClearPreviousMenu();
	m_eCurMenuState = eMenuStateTutorial;
	int iCenterX = m_poDriver->getScreenSize().Width / 2;
	int iCenterY = m_poDriver->getScreenSize().Height / 2;

	// title
	int iTextWidth = 360;
	int iCurYPos = iCenterY - 220;
	irr::gui::IGUIStaticText * poTitleText = m_poGui->addStaticText(L"Tutorial",  GetCenteredRect(iCenterX, iCurYPos, 150, 40), false, false);
	poTitleText->setOverrideFont( m_apoFonts[ eGuiFontLarge ] );
	poTitleText->setTextAlignment( irr::gui::EGUIA_CENTER, irr::gui::EGUIA_UPPERLEFT );

	iCurYPos += 60;
	irr::gui::IGUIButton * poDoneBut = m_poGui->addButton( GetCenteredRect(iCenterX, iCurYPos, (130 * m_f32ScaleWidth), (34 * m_f32ScaleHeight)), 0, EGUI_TUTORIAL_DONE, L"Continue");
	poDoneBut->setOverrideFont( m_apoFonts[ eGuiFontMedium ] );
	poDoneBut->setImage( m_apoGuiImages[ eGuiImageButton128x32 ] );
	poDoneBut->setUseAlphaChannel(true);
	poDoneBut->setScaleImage( true );

	iCurYPos += ( 60 * m_f32ScaleHeight);
	irr::gui::IGUIStaticText * poTutText = m_poGui->addStaticText(L"1.) Tilt phone forward and backward to",  GetCenteredRect(iCenterX, iCurYPos, iTextWidth, 40), false, false);
	poTutText->setOverrideFont( m_apoFonts[ eGuiFontMedium ] );
	iCurYPos += 20;
	poTutText = m_poGui->addStaticText(L"      tilt the earth.",  GetCenteredRect(iCenterX, iCurYPos, iTextWidth, 40), false, false);
	poTutText->setOverrideFont( m_apoFonts[ eGuiFontMedium ] );
	iCurYPos += 30;
	poTutText = m_poGui->addStaticText(L"2.) Launch comet at earth.",  GetCenteredRect(iCenterX, iCurYPos, iTextWidth, 40), false, false);
	poTutText->setOverrideFont( m_apoFonts[ eGuiFontMedium ] );
	iCurYPos += 30;
	poTutText = m_poGui->addStaticText(L"3.) Comets that hit land increases earth ",  GetCenteredRect(iCenterX, iCurYPos, iTextWidth, 40), false, false);
	poTutText->setOverrideFont( m_apoFonts[ eGuiFontMedium ] );
	iCurYPos += 20;
	poTutText = m_poGui->addStaticText(L"      damage and increase score.",  GetCenteredRect(iCenterX, iCurYPos, iTextWidth, 40), false, false);
	poTutText->setOverrideFont( m_apoFonts[ eGuiFontMedium ] );
	iCurYPos += 30;
	poTutText = m_poGui->addStaticText(L"4.) Comets that hit ocean do no damage ",  GetCenteredRect(iCenterX, iCurYPos, iTextWidth, 40), false, false);
	poTutText->setOverrideFont( m_apoFonts[ eGuiFontMedium ] );
	iCurYPos += 20;
	poTutText = m_poGui->addStaticText(L"      and decrease score.",  GetCenteredRect(iCenterX, iCurYPos, iTextWidth, 40), false, false);
	poTutText->setOverrideFont( m_apoFonts[ eGuiFontMedium ] );
	iCurYPos += 30;
	poTutText = m_poGui->addStaticText(L"5.) Hitting red asteroid with red comet ",  GetCenteredRect(iCenterX, iCurYPos, iTextWidth, 40), false, false);
	poTutText->setOverrideFont( m_apoFonts[ eGuiFontMedium ] );
	iCurYPos += 20;
	poTutText = m_poGui->addStaticText(L"      increases damage the comet can do.",  GetCenteredRect(iCenterX, iCurYPos, iTextWidth, 40), false, false);
	poTutText->setOverrideFont( m_apoFonts[ eGuiFontMedium ] );
	iCurYPos += 30;
	poTutText = m_poGui->addStaticText(L"6.) Hitting blue asteroid with blue comet ",  GetCenteredRect(iCenterX, iCurYPos, iTextWidth, 40), false, false);
	poTutText->setOverrideFont( m_apoFonts[ eGuiFontMedium ] );
	iCurYPos += 20;
	poTutText = m_poGui->addStaticText(L"      increases damage the comet can do.",  GetCenteredRect(iCenterX, iCurYPos, iTextWidth, 40), false, false);
	poTutText->setOverrideFont( m_apoFonts[ eGuiFontMedium ] );

	return 0;
}
//------------------------------------------------------------------------------
//! build menu to show game over but not high score
RCODE DtwStateMenu::InitGameOver( void )
{
	ClearPreviousMenu();
	m_eCurMenuState = eMenuStateGameOver;
	int iCenterX = m_poDriver->getScreenSize().Width / 2;
	int iCenterY = m_poDriver->getScreenSize().Height / 2;

	// title
	int iTextWidth = 310;
	int iCurYPos = iCenterY - (100 * m_f32ScaleHeight );
	irr::gui::IGUIStaticText * poTitleText = m_poGui->addStaticText(L"GAME OVER",  GetCenteredRect(iCenterX, iCurYPos, iTextWidth, 40), false, false);
	poTitleText->setOverrideFont( m_apoFonts[ eGuiFontLarge ] );
	poTitleText->setTextAlignment( irr::gui::EGUIA_CENTER, irr::gui::EGUIA_UPPERLEFT );

	iCurYPos += 60  * m_f32ScaleHeight;
	irr::gui::IGUIButton * poDoneBut = m_poGui->addButton( GetCenteredRect(iCenterX, iCurYPos, (130 * m_f32ScaleWidth), (40 * m_f32ScaleHeight)), 0, EGUI_GAME_OVER_DONE, L"Continue");
	poDoneBut->setOverrideFont( m_apoFonts[ eGuiFontMedium ] );
	poDoneBut->setImage( m_apoGuiImages[ eGuiImageButton128x32 ] );
	poDoneBut->setUseAlphaChannel(true);
	poDoneBut->setScaleImage( true );

	iCurYPos += 60 * m_f32ScaleHeight;
	irr::core::stringw strScore;
	switch( m_poIrrBase->m_iGameLevel )
	{
	case 1:
		strScore.Format( "EASY LEVEL SCORE: %d", m_poIrrBase->m_iGameScore );
		break;
	case 2:
		strScore.Format( "MEDIUM LEVEL SCORE: %d", m_poIrrBase->m_iGameScore );
		break;
	case 3:
		strScore.Format( "HARD LEVEL SCORE: %d", m_poIrrBase->m_iGameScore );
		break;
	}

	irr::gui::IGUIStaticText * poTutText = m_poGui->addStaticText(strScore.c_str(),  GetCenteredRect(iCenterX, iCurYPos, iTextWidth, 40), false, false);
	poTutText->setOverrideFont( m_apoFonts[ eGuiFontMedium ] );
	return 0;
}
//------------------------------------------------------------------------------
//! build menu to show game over with high score
RCODE DtwStateMenu::InitGameOverHighScore( void )
{
	ClearPreviousMenu();
	m_eCurMenuState = eMenuStateGameOverHighScore;
	int iCenterX = m_poDriver->getScreenSize().Width / 2;
	int iCenterY = m_poDriver->getScreenSize().Height / 2;

	// title
	int iTextWidth = 360;
	int iCurYPos = iCenterY - 180 * m_f32ScaleHeight;
	irr::gui::IGUIStaticText * poTitleText = m_poGui->addStaticText(L"CONGRADUATIONS",  GetCenteredRect(iCenterX, iCurYPos, 310, 40), false, false);
	poTitleText->setOverrideFont( m_apoFonts[ eGuiFontLarge ] );
	poTitleText->setTextAlignment( irr::gui::EGUIA_CENTER, irr::gui::EGUIA_UPPERLEFT );
	iCurYPos += 50 * m_f32ScaleHeight;
	poTitleText = m_poGui->addStaticText(L"YOU HAVE HIGH SCORE",  GetCenteredRect(iCenterX, iCurYPos, 360, 40), false, false);
	poTitleText->setOverrideFont( m_apoFonts[ eGuiFontLarge ] );
	poTitleText->setTextAlignment( irr::gui::EGUIA_CENTER, irr::gui::EGUIA_UPPERLEFT );
	iCurYPos += 50 * m_f32ScaleHeight;


	irr::core::stringw strScore;
	switch( m_poIrrBase->m_iGameLevel )
	{
	case 1:
		strScore.Format( "EASY LEVEL SCORE: %d", m_poIrrBase->m_iGameScore );
		break;
	case 2:
		strScore.Format( "MEDIUM LEVEL SCORE: %d", m_poIrrBase->m_iGameScore );
		break;
	case 3:
		strScore.Format( "HARD LEVEL SCORE: %d", m_poIrrBase->m_iGameScore );
		break;
	}
	poTitleText = m_poGui->addStaticText(strScore.c_str(),  GetCenteredRect(iCenterX, iCurYPos, 360, 40), false, false);
	poTitleText->setOverrideFont( m_apoFonts[ eGuiFontMedium ] );
	poTitleText->setTextAlignment( irr::gui::EGUIA_CENTER, irr::gui::EGUIA_UPPERLEFT );
	iCurYPos += 50 * m_f32ScaleHeight;

	irr::gui::IGUIButton * poDoneBut = m_poGui->addButton( GetCenteredRect(iCenterX, iCurYPos, 130 * m_f32ScaleWidth, 40  * m_f32ScaleHeight), 0, EGUI_GAME_OVER_HIGH_SCORE_ADD_SCORE, L"Continue");
	poDoneBut->setOverrideFont( m_apoFonts[ eGuiFontMedium ] );
	poDoneBut->setImage( m_apoGuiImages[ eGuiImageButton128x32 ] );
	poDoneBut->setUseAlphaChannel(true);
	poDoneBut->setScaleImage( true );
	iCurYPos += 60* m_f32ScaleHeight;
	return 0;
}
//------------------------------------------------------------------------------
//! build menu to allow user to add high score
RCODE DtwStateMenu::InitAddHighScore( void )
{
	ClearPreviousMenu();
	m_eCurMenuState = eMenuStateAddHighScore;
	int iCenterX = m_poDriver->getScreenSize().Width / 2;
	int iCenterY = m_poDriver->getScreenSize().Height / 2;

	// title
	int iTextWidth = 310;
	int iCurYPos = iCenterY - 180;
	irr::gui::IGUIStaticText * poTitleText = m_poGui->addStaticText(L"ENTER YOUR NAME",  GetCenteredRect(iCenterX, iCurYPos, iTextWidth, 50), false, false);
	poTitleText->setOverrideFont( m_apoFonts[ eGuiFontLarge ] );
	poTitleText->setTextAlignment( irr::gui::EGUIA_CENTER, irr::gui::EGUIA_UPPERLEFT );
	iCurYPos += 60;
	poTitleText = m_poGui->addStaticText(L"FOR HIGH SCORE",  GetCenteredRect(iCenterX, iCurYPos, iTextWidth, 50), false, false);
	poTitleText->setOverrideFont( m_apoFonts[ eGuiFontLarge ] );
	poTitleText->setTextAlignment( irr::gui::EGUIA_CENTER, irr::gui::EGUIA_UPPERLEFT );
	iCurYPos += 70;

	// name
	m_poAddHighScoreNameEditBox = m_poGui->addEditBox(L"",  GetCenteredRect(iCenterX, iCurYPos, iTextWidth, 40), true, NULL, EGUI_ADD_SCORE_EDIT_BOX );
	m_poAddHighScoreNameEditBox->setOverrideFont(  m_poIrrBase->m_poDefaultFont );
	//m_poAddHighScoreNameEdit->setTextAlignment( irr::gui::EGUIA_CENTER, irr::gui::EGUIA_UPPERLEFT );
	iCurYPos += 60;
	int iButWidth = m_poDriver->getScreenSize().Width / 10;
	int iButHeight = 20;
	if( m_poDriver->getScreenSize().Height > 500 )
	{
		int iButHeight = 20;
	}
	irr::gui::IGUIButton * poTempBut;
	wchar_t as16KeyButName[3];
	for( int i = 0; i < 10; i++ )
	{
		as16KeyButName[0] = m_au8QwertyKeys[i];
		as16KeyButName[1] = 0;
		poTempBut = m_poGui->addButton( irr::core::rect<irr::s32>(
			i * iButWidth, iCurYPos, (i * iButWidth) + iButWidth, iCurYPos + iButHeight), 
			0, EGUI_KEY_BASE_ID + i, as16KeyButName);
		poTempBut->setOverrideFont( m_poIrrBase->m_poDefaultFont );
	}
	iCurYPos += iButHeight + 20;
	for( int i = 10; i < 19; i++ )
	{
		as16KeyButName[0] = m_au8QwertyKeys[i];
		as16KeyButName[1] = 0;
		poTempBut = m_poGui->addButton( irr::core::rect<irr::s32>(
			((i -10) * iButWidth) + (iButWidth>>1), iCurYPos, ((i -10) * iButWidth) + (iButWidth>>1) + iButWidth, iCurYPos + iButHeight), 
			0, EGUI_KEY_BASE_ID + i, as16KeyButName);
		poTempBut->setOverrideFont( m_poIrrBase->m_poDefaultFont );
	}
	iCurYPos += iButHeight + 20;
	for( int i = 19; i < 27; i++ )
	{
		as16KeyButName[0] = m_au8QwertyKeys[i];
		as16KeyButName[1] = 0;
		poTempBut = m_poGui->addButton( irr::core::rect<irr::s32>(
			((i -18)* iButWidth), iCurYPos, ((i -18) * iButWidth) + iButWidth, iCurYPos + iButHeight), 
			0, EGUI_KEY_BASE_ID + i, as16KeyButName);
		poTempBut->setOverrideFont( m_poIrrBase->m_poDefaultFont );
	}
	iCurYPos += 20 + iButHeight + 70;
	irr::gui::IGUIButton * poDoneBut = m_poGui->addButton( GetCenteredRect(iCenterX, iCurYPos, (130 * m_f32ScaleWidth), (34 * m_f32ScaleHeight)), 0, EGUI_ADD_SCORE_DONE, L"Continue");
	poDoneBut->setOverrideFont( m_apoFonts[ eGuiFontMedium ] );
	poDoneBut->setImage( m_apoGuiImages[ eGuiImageButton128x32 ] );
	poDoneBut->setUseAlphaChannel(true);
	poDoneBut->setScaleImage( true );

	iCurYPos += 60;
	return 0;
}
//------------------------------------------------------------------------------
//! build menue to allow user to pick which level of high scores to view
RCODE DtwStateMenu::InitHighScoreLevel( void )
{
	ClearPreviousMenu();
	m_eCurMenuState = eMenuStateHighScoreLevel;
	int iCenterX = m_poDriver->getScreenSize().Width / 2;
	int iCenterY = m_poDriver->getScreenSize().Height / 2;

	// title
	int iTextWidth = 360;
	int iCurYPos = iCenterY - 200;
	irr::gui::IGUIStaticText * poTitleText = m_poGui->addStaticText(L"PICK WHICH LEVEL",  GetCenteredRect(iCenterX, iCurYPos, 350, 40), false, false);
	poTitleText->setOverrideFont( m_apoFonts[ eGuiFontLarge ] );
	poTitleText->setTextAlignment( irr::gui::EGUIA_CENTER, irr::gui::EGUIA_UPPERLEFT );
	iCurYPos += 40;
	poTitleText = m_poGui->addStaticText(L"OF HIGH SCORE TO VIEW",  GetCenteredRect(iCenterX, iCurYPos, 350, 40), false, false);
	poTitleText->setOverrideFont( m_apoFonts[ eGuiFontLarge ] );
	poTitleText->setTextAlignment( irr::gui::EGUIA_CENTER, irr::gui::EGUIA_UPPERLEFT );
	iCurYPos += 70;

	// setup buttons
	irr::gui::IGUIButton * poEasyLevelBut	= m_poGui->addButton( GetCenteredRect( iCenterX, iCurYPos, (130 * m_f32ScaleWidth ), (40 * m_f32ScaleHeight)), 0, EGUI_PICK_HIGHSCORE_EASY, L"Easy" );
	iCurYPos += (50 * m_f32ScaleHeight);
	irr::gui::IGUIButton * poMediumLevelBut	= m_poGui->addButton( GetCenteredRect( iCenterX, iCurYPos, (130 * m_f32ScaleWidth ), (40 * m_f32ScaleHeight)), 0, EGUI_PICK_HIGHSCORE_MEDIUM, L"Medium" );
	iCurYPos += (50 * m_f32ScaleHeight);
	irr::gui::IGUIButton * poHardLevelBut	= m_poGui->addButton( GetCenteredRect( iCenterX, iCurYPos, (130 * m_f32ScaleWidth ), (40 * m_f32ScaleHeight)), 0, EGUI_PICK_HIGHSCORE_HARD, L"Hard" );
	iCurYPos += (50 * m_f32ScaleHeight);
	poEasyLevelBut->setImage( m_apoGuiImages[ eGuiImageButton128x32 ] );
	poEasyLevelBut->setUseAlphaChannel(true);
	poEasyLevelBut->setOverrideFont( GetFont( m_eDefaultFontSize ) );
	poEasyLevelBut->setScaleImage( true );

	poMediumLevelBut->setImage( m_apoGuiImages[ eGuiImageButton128x32 ] );
	poMediumLevelBut->setUseAlphaChannel(true);
	poMediumLevelBut->setOverrideFont( GetFont( m_eDefaultFontSize ) );
	poMediumLevelBut->setScaleImage( true );

	poHardLevelBut->setImage( m_apoGuiImages[ eGuiImageButton128x32 ] );
	poHardLevelBut->setUseAlphaChannel(true);
	poHardLevelBut->setOverrideFont( GetFont( m_eDefaultFontSize ) );
	poHardLevelBut->setScaleImage( true );

	return 0;
}
//------------------------------------------------------------------------------
//! build menu showing high scores
RCODE DtwStateMenu::InitMenuHighScores( void )
{
	ClearPreviousMenu();
	m_eCurMenuState = eMenuStateHighScores;
	int iCenterX = m_poDriver->getScreenSize().Width / 2;
	int iCenterY = m_poDriver->getScreenSize().Height / 2;

	// title
	int iTextWidth = 360;
	int iCurYPos = iCenterY - (220 * m_f32ScaleHeight);

	irr::gui::IGUIStaticText * poTitleText;
	poTitleText = m_poGui->addStaticText(L"HIGH SCORES",  GetCenteredRect(iCenterX, iCurYPos, 320, 40), false, false);
	poTitleText->setOverrideFont( m_apoFonts[ eGuiFontLarge ] );
	poTitleText->setTextAlignment( irr::gui::EGUIA_CENTER, irr::gui::EGUIA_UPPERLEFT );
	iCurYPos += (30 * m_f32ScaleHeight);
	switch( m_poIrrBase->m_iGameLevel )
	{
	case 1:
		poTitleText = m_poGui->addStaticText(L"EASY LEVEL",  GetCenteredRect(iCenterX, iCurYPos, 320, 40), false, false);
		poTitleText->setOverrideFont( m_apoFonts[ eGuiFontMedium ] );
		poTitleText->setTextAlignment( irr::gui::EGUIA_CENTER, irr::gui::EGUIA_UPPERLEFT );
		break;
	case 2:
		poTitleText = m_poGui->addStaticText(L"MEDIUM LEVEL",  GetCenteredRect(iCenterX, iCurYPos, 320, 40), false, false);
		poTitleText->setOverrideFont( m_apoFonts[ eGuiFontMedium ] );
		poTitleText->setTextAlignment( irr::gui::EGUIA_CENTER, irr::gui::EGUIA_UPPERLEFT );
		break;
	case 3:
		poTitleText = m_poGui->addStaticText(L"HARD LEVEL",  GetCenteredRect(iCenterX, iCurYPos, 320, 40), false, false);
		poTitleText->setOverrideFont( m_apoFonts[ eGuiFontMedium ] );
		poTitleText->setTextAlignment( irr::gui::EGUIA_CENTER, irr::gui::EGUIA_UPPERLEFT );
		break;
	}
	iCurYPos += (30 * m_f32ScaleHeight);
	irr::gui::IGUIButton * poDoneBut = m_poGui->addButton( GetCenteredRect(iCenterX, iCurYPos, (130 * m_f32ScaleWidth), (34 * m_f32ScaleHeight)), 0, EGUI_SHOW_HIGHSCORE_BACK_BUT, L"DONE");
	poDoneBut->setOverrideFont( m_apoFonts[ eGuiFontMedium ] );
	poDoneBut->setImage( m_apoGuiImages[ eGuiImageButton128x32 ] );
	poDoneBut->setUseAlphaChannel(true);
	poDoneBut->setScaleImage( true );

	iCurYPos += (40 * m_f32ScaleHeight);
	irr::core::stringw strHdr = "SCORE  TIME  NAME";
	irr::gui::IGUIStaticText * poHdrText = m_poGui->addStaticText(strHdr.c_str(),  GetCenteredRect(iCenterX, iCurYPos, 320, 40), false, false);
	poHdrText->setOverrideFont( m_apoFonts[ eGuiFontLarge ] );
	//poTitleText->setTextAlignment( irr::gui::EGUIA_CENTER, irr::gui::EGUIA_UPPERLEFT );
	iCurYPos += 30;

	switch( m_poIrrBase->m_iGameLevel )
	{
	case 1:
		DisplayHighScores( iCenterX, iCurYPos, g_HighScoresImp.m_aoEasyHighScores );
		break;
	case 2:
		DisplayHighScores( iCenterX, iCurYPos, g_HighScoresImp.m_aoMediumHighScores );
		break;
	case 3:
		DisplayHighScores( iCenterX, iCurYPos, g_HighScoresImp.m_aoHardHighScores );
		break;
	}

	return 0;
}
//------------------------------------------------------------------------------
//! display high scores
void DtwStateMenu::DisplayHighScores( int iCenterX, int iCurYPos, irr::core::array<HighScoreEntry>& aoScoreEntries )
{

	irr::core::stringw strEntry;
	irr::core::stringw strScore;
	irr::core::stringw strTime;
	irr::core::stringw strName;
	for( int i = 0; i < aoScoreEntries.size(); i++ )
	{
		aoScoreEntries[i].GetFormatedHighScore( strEntry );
		strScore.Format( "%d", aoScoreEntries[i].m_iScore );
		strTime.Format( "%d", aoScoreEntries[i].m_iPlayTime );
		strName =  aoScoreEntries[i].m_strUserName.c_str();

		irr::gui::IGUIStaticText * poText = m_poGui->addStaticText(strScore.c_str(),  GetCenteredRect(iCenterX - 100, iCurYPos, 100, 40), false, false);
		poText->setOverrideFont( m_apoFonts[ eGuiFontMedium ] );
		poText->setTextAlignment( irr::gui::EGUIA_UPPERLEFT, irr::gui::EGUIA_UPPERLEFT );

		poText = m_poGui->addStaticText(strTime.c_str(),  GetCenteredRect(iCenterX - 0, iCurYPos, 100, 40), false, false);
		poText->setOverrideFont( m_apoFonts[ eGuiFontMedium ] );
		poText->setTextAlignment( irr::gui::EGUIA_UPPERLEFT, irr::gui::EGUIA_UPPERLEFT );

		poText = m_poGui->addStaticText(strName.c_str(),  GetCenteredRect(iCenterX + 120, iCurYPos, 180, 40), false, false);
		poText->setOverrideFont( m_apoFonts[ eGuiFontMedium ] );
		poText->setTextAlignment( irr::gui::EGUIA_UPPERLEFT, irr::gui::EGUIA_UPPERLEFT );
		iCurYPos += 30;
	}
}

